package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.AddNursingProjectDto;
import com.zzyl.dto.NursingProjectQueryDto;
import com.zzyl.dto.UpdateNursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NursingProjectServiceImpl  implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> pageQuery(NursingProjectQueryDto dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        Page<NursingProjectVo> page = nursingProjectMapper.pageQuery(dto);
        return PageResponse.of(page, NursingProjectVo.class);
    }

    @Override
    public void add(AddNursingProjectDto dto) {
        NursingProject nursingProject = BeanUtil.copyProperties(dto, NursingProject.class);
        nursingProject.setCreateTime(LocalDateTime.now());
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProjectMapper.insert(nursingProject);
    }

    @Override
    public NursingProject getById(Long id) {
        return nursingProjectMapper.selectById(id);
    }

    @Override
    public void update(UpdateNursingProjectDto dto) {
        NursingProject nursingProject = BeanUtil.copyProperties(dto, NursingProject.class);
        nursingProjectMapper.update(nursingProject);
    }

    @Override
    public void delete(Long id) {
        nursingProjectMapper.delete(id);
    }

    @Override
    public void status(Long id, Integer status) {
        NursingProject nursingProject = new NursingProject();
        nursingProject.setId(id);
        nursingProject.setStatus(status);
        nursingProjectMapper.update(nursingProject);
    }

    @Override
    public List<NursingProject> all() {
        return nursingProjectMapper.all();
    }
}
